package net.expectx.pay.rpc.service.impl;

import net.expectx.common.single.base.BaseResult;
import net.expectx.common.single.base.BaseServiceImpl;
import net.expectx.pay.dao.bean.SystemTypeExample;
import net.expectx.pay.dao.mapper.SystemTypeGroupMapper;
import net.expectx.pay.dao.bean.SystemTypeGroup;
import net.expectx.pay.dao.mapper.SystemTypeMapper;
import net.expectx.pay.rpc.api.SystemTypeGroupService;
import net.expectx.pay.dao.bean.SystemTypeGroupExample;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;

/**
 * SystemTypeGroupService实现
 * @author lijian
 * @date 2019/7/3
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SystemTypeGroupServiceImpl extends BaseServiceImpl<SystemTypeGroup, SystemTypeGroupExample> implements SystemTypeGroupService {

    private static final Logger LOGGER = Logger.getLogger(SystemTypeGroupServiceImpl.class);

    @Autowired
    private DataSourceTransactionManager transactionManager;
    @Autowired
    SystemTypeGroupMapper systemTypeGroupMapper;
    @Autowired
    SystemTypeMapper systemTypeMapper;

    @Override
    public BaseResult physicalRemove(Byte isDeleted, SystemTypeGroupExample systemTypeGroupExample, SystemTypeExample systemTypeExample) {
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        TransactionStatus status = transactionManager.getTransaction(def);
        try {
            systemTypeGroupMapper.physicalRemoveByExample(isDeleted, systemTypeGroupExample);
            systemTypeMapper.physicalRemoveByExample(isDeleted, systemTypeExample);
            transactionManager.commit(status);
            LOGGER.info("删除成功");
            return new BaseResult(true, "删除成功", null);
        } catch (Exception e1) {
            LOGGER.error("系统错误:" + e1.getLocalizedMessage());
            transactionManager.rollback(status);
            return new BaseResult(false, "系统错误:" + e1.getLocalizedMessage(), null);
        }
    }
}
